home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-19 | 7.4 KB | 234 lines | [TEXT/CWIE] |
- /*
- File: AbstractDocument.c
-
- Contains: Abstract base class for documents
-
- Written by: Greg Anderson
-
- Copyright: © 1993 by Greg Anderson, all rights reserved.
-
- 3/31/93 ga
-
- To Do:
- */
-
- #include "AbstractDocument.h"
-
- #include <AERegistry.h>
-
- #include "Exceptions.h"
-
- TAbstractDocument* gOpenDocumentList = nil;
-
- #define clAbstractDocument 42
-
- #pragma segment ObjectResident
- ImplementSmallClassData(TAbstractDocument, clAbstractDocument);
-
-
- //----------------------------------------------------------------------------------------
- // FirstOpenDocument:
- //----------------------------------------------------------------------------------------
- TAbstractDocument* FirstOpenDocument()
- {
- return gOpenDocumentList;
- } // FirstOpenDocument
-
- //----------------------------------------------------------------------------------------
- // LastOpenDocument:
- //----------------------------------------------------------------------------------------
- TAbstractDocument* LastOpenDocument()
- {
- TAbstractDocument* doc = gOpenDocumentList;
- TAbstractDocument* nextDoc = doc;
-
- while(nextDoc != nil)
- {
- doc = nextDoc;
- nextDoc = doc->NextDocument();
- }
-
- return doc;
- } // LastOpenDocument
-
-
-
- //========================================================================================
- // CLASS TAbstractDocument
- //========================================================================================
-
-
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::TAbstractDocument:
- //----------------------------------------------------------------------------------------
- TAbstractDocument::TAbstractDocument()
- {
- fCloseRequested = false;
- this->PushOnDocumentList();
- }
-
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::~TAbstractDocument:
- //----------------------------------------------------------------------------------------
- TAbstractDocument::~TAbstractDocument()
- {
- this->RemoveFromDocumentList();
- }
-
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::RemoveFromDocumentList:
- //----------------------------------------------------------------------------------------
- void TAbstractDocument::RemoveFromDocumentList()
- {
- //
- // Remove ourselves from the linked list
- //
- if(fNextDocument != nil)
- fNextDocument->fPreviousDocument = fPreviousDocument;
- if(fPreviousDocument != nil)
- fPreviousDocument->fNextDocument = fNextDocument;
- //
- // If we are on the head of the list, then fix up the head pointer
- //
- else // (fPreviousDocument == nil)
- {
- if(gOpenDocumentList == this)
- gOpenDocumentList = fNextDocument;
- }
-
- //
- // Clear our links
- //
- fNextDocument = nil;
- fPreviousDocument = nil;
- } // TAbstractDocument::RemoveFromDocumentList
-
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::IAbstractDocument:
- //----------------------------------------------------------------------------------------
- void TAbstractDocument::IAbstractDocument()
- {
- //
- // Nothing to do here
- //
- } // TAbstractDocument::IAbstractDocument
-
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::Clone:
- //
- // Derived classes should call 'new' themselves, then clone the fields of the new object
- //----------------------------------------------------------------------------------------
- TAbstractScriptableObject* TAbstractDocument::Clone()
- {
- TAbstractDocument* clonedDocument = (TAbstractDocument*)TAbstractScriptableObject::Clone();
-
- //
- // Overwrite our old previous and next links
- //
- clonedDocument->PushOnDocumentList();
-
- return clonedDocument;
- } // TAbstractDocument::Clone
-
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::PushOnDocumentList:
- //----------------------------------------------------------------------------------------
- void TAbstractDocument::PushOnDocumentList()
- {
- //
- // Push ourselves on the list of open documents
- //
- if(gOpenDocumentList)
- gOpenDocumentList->fPreviousDocument = this;
- fNextDocument = gOpenDocumentList;
- gOpenDocumentList = this;
-
- //
- // Clear our 'previous' list
- //
- fPreviousDocument = nil;
- } // TAbstractDocument::PushOnDocumentList
-
- #if 0
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::operator=:
- //----------------------------------------------------------------------------------------
- TAbstractDocument& TAbstractDocument::operator=(const TAbstractDocument& rhs)
- {
- //
- // Remember what our forward and backward links used to be
- //
- TAbstractDocument* nextDocument = fNextDocument;
- TAbstractDocument* previousDocument = fPreviousDocument;
-
- //
- // Call the inherited operator=, which copies all of the
- // fields from 'rhs' into this object
- //
- TAbstractScriptableObject::operator=(rhs);
-
- //
- // Now put our forward and backward links back the way they were
- // If this assignment is being done as a result of a clone, then
- // TAbstractDocument::Clone will fix up the next and previous links.
- //
- fNextDocument = nextDocument;
- fPreviousDocument = previousDocument;
-
- return *this;
- } // TAbstractDocument::operator=
- #endif
-
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::DocumentFSSpecification
- //
- // Return the TFSSpecification for the file this document is saved in, if any.
- //----------------------------------------------------------------------------------------
- Boolean TAbstractDocument::DocumentFSSpecification(TFSSpecification&) const
- {
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::ObjectClass:
- //----------------------------------------------------------------------------------------
- DescType TAbstractDocument::ObjectClass(const TAETransaction&, Boolean /*recordedClass*/)
- {
- return cDocument;
- } // TAbstractDocument::ObjectClass
-
- //----------------------------------------------------------------------------------------
- // TAbstractDocument::DerivedFromOSLClass:
- //----------------------------------------------------------------------------------------
- Boolean TAbstractDocument::DerivedFromOSLClass(const TAETransaction& t, DescType objectClass)
- {
- return ((objectClass == cDocument) || TAbstractScriptableObject::DerivedFromOSLClass(t, objectClass));
- } // TAbstractDocument::DerivedFromOSLClass
-
- //================================================================================
- // Class TDocumentLoop
- //================================================================================
-
- //----------------------------------------------------------------------------------------
- // TDocumentLoop::~TDocumentLoop
- //----------------------------------------------------------------------------------------
- TDocumentLoop::~TDocumentLoop()
- {
- }// TDocumentLoop::~TDocumentLoop
-
- //----------------------------------------------------------------------------------------
- // TDocumentLoop::RemoveCurrentDocument
- //----------------------------------------------------------------------------------------
- TAbstractDocument* TDocumentLoop::RemoveCurrentDocument(const TAETransaction& t)
- {
- TAbstractDocument* removee = this->CurrentDocument();
- if(removee)
- {
- this->Next(t);
- removee->RemoveFromDocumentList();
- }
- fRemovedCurrent = true;
- return removee;
- } // TDocumentLoop::RemoveCurrentDocument
-
-